package com.sample.springbatch.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 对JOB的监听实现类
 * Created by zwg on 2017/7/20.
 */
@Component
public class MyJobListener extends JobExecutionListenerSupport {

    private static final Logger logger = LoggerFactory.getLogger(MyJobListener.class);

    @Autowired
    private MapExecutionTracker mapExecutionTracker;

    @Override
    public void beforeJob(JobExecution jobExecution) {
        logger.info("job[{}] start run.",jobExecution.getJobInstance().getJobName());

        mapExecutionTracker.saveJobExecution(jobExecution);
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        logger.info("job[{}] end run.",jobExecution.getJobInstance().getJobName());

        mapExecutionTracker.saveJobExecution(jobExecution);
    }

}
